package demo.src.main.com.example.mq.mqproducer;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("")
public class IndexController {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    @RequestMapping("/index")
    public String indexView(){
        return "index";
    }

    //MQ 的rabbittemplet 进行消息发送
    @RequestMapping("/sendMessage")
    public String send(){

    String msg="通过整合spring发送的消息";

    this.rabbitTemplate.setExchange("springExchange");
    this.rabbitTemplate.setRoutingKey("testKey");
    this.rabbitTemplate.convertAndSend(msg);
        return "index";
    }



}
